import type { CartItem } from "@/types/cart"
import { http } from "@/utils/http"

/**
 *
 * @param data 请求体参数
 * @returns
 */
export const postMemberCartAPI = (data: { skuId: string, count: number }) => {
  return http({
    method: 'POST',
    url: '/member/cart',
    data
  })
}

// 获取购物车列表
export const getMemberCartAPI = () => {
  return http<CartItem[]>({
    method: 'GET',
    url: '/member/cart'
  })
}

/**
 *
 * @param data 请求体参数 ids为sku的id
 * @returns
 */
// 删除购物车数据
export const deleteMemberCartAPI = (data: { ids: string[] }) => {
  return http({
    method: 'DELETE', url: '/member/cart', data
  })
}

// 修改购物车数量
/**
 *
 * @param skuId SKUID
 * @param data selected 选中状态 count 商品数量
 * @returns
 */
export const putMemberCartBySkuAPI = (skuId: string, data: { selected?: boolean, count?: number }) => {
  return http({
    method: 'PUT',
    url: `/member/cart/${skuId}`,
    data
  })
}
/**
 *
 * @param data 请求体数据 selected选中状态
 * @returns
 */
export const putMemberCartSelectedAPI = (data: { selected: boolean }) => {
  return http({
    method: 'PUT',
    url: '/member/cart/selected',
    data
  })
}
